package test.composite;

import dk.au.cs.peterbn.annotations.Pattern;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: peter
 * Date: 10/28/11
 * Time: 12:24 PM
 * To change this template use File | Settings | File Templates.
 */
@Pattern(id = "test.composite", name = "gof:Composite", role = "Composite")
public class Composite extends Component {

    private List<Component> children = new ArrayList<Component>();
    @Override
    public void operation() {
        for (Component child : children) {
            child.operation();
        }
    }

    @Override
    public void add(Component child) {
        children.add(child);

    }

    @Override
    public void remove(Component child) {
        children.remove(child);
    }

    @Override
    public Component getChild(int index) {
        return children.get(index);
    }
}
